package com.stylefeng.guns.modular.netcar.service.impl;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.model.CommonKeyValue;
import com.stylefeng.guns.core.model.Pager;
import com.stylefeng.guns.modular.netcar.dao.OrderRefundInfMapper;
import com.stylefeng.guns.modular.netcar.model.OrderRefundInf;
import com.stylefeng.guns.modular.netcar.service.IOrderRefundInfService;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.toolkit.IdWorker;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**

 * 退款记录表 Service 实现 
 * @author 张亚林
 * @Date 2019-03-08 10:34
 */
@Service
public class OrderRefundInfServiceImpl extends ServiceImpl<OrderRefundInfMapper,OrderRefundInf> implements IOrderRefundInfService {

    @Resource
    private OrderRefundInfMapper orderRefundInfMapper;

    /**
     * 删除退款记录表
     * @param orderRefundInf
     * @return     
     */
    @Transactional
    public int deleteOrderRefundInf(OrderRefundInf orderRefundInf,String token)throws Exception{
        if(orderRefundInf==null ){
            throw new RuntimeException("参数不全！");
        }
        return this.orderRefundInfMapper.deleteOrderRefundInf(orderRefundInf);
    }
    /**
     * 批量删除退款记录表
     * @param ids 主键ID数组
     * @return 
     */
    @Transactional
    public int deleteBatchOrderRefundInf(String[] ids,String token)throws Exception{
        return this.orderRefundInfMapper.deleteBatchOrderRefundInf(ids);
    }
    /**
     * 查询退款记录表列表
     * @param orderRefundInf 退款记录表对象
     * @return
     */
    public List<OrderRefundInf> selectListOrderRefundInf(OrderRefundInf orderRefundInf,String token)throws Exception{
        return  this.orderRefundInfMapper.selectListOrderRefundInf(orderRefundInf);
    }
    /**
	 * 分页查询退款记录表列表
     * @param pager 分页对象
     * @return
     */     
    public  Map pageListOrderRefundInf(Pager pager,String token) throws Exception{
        Page page=new Page(pager.getPageNumber(),pager.getPageSize());
        page.setRecords(orderRefundInfMapper.selectListOrderRefundInf(page,(OrderRefundInf)pager.getObj()));
        List<OrderRefundInf> list = page.getRecords();
        Map mapDate = new HashMap();
        mapDate.put("rows", list);
        mapDate.put("total", page.getTotal());
        mapDate.put("page", page.getCurrent());
        mapDate.put("pageCount", page.getPages());
        return mapDate;
    }
    /**
     * 同一个事务 互斥锁查询
     * @param orderRefundInf 退款记录表对象
     * @return 
     */
    public  List<OrderRefundInf> selectListOrderRefundInfForUpdate(OrderRefundInf orderRefundInf)throws Exception{
        return  this.orderRefundInfMapper.selectListOrderRefundInfForUpdate(orderRefundInf);
    }
    /**
     * 通过主键id查询的退款记录表列表
     * @param id 主键id
     * @return     
     */
    public  OrderRefundInf findOrderRefundInfById(String id,String token)throws Exception{
        return  this.orderRefundInfMapper.findOrderRefundInfById(id);
    }

    /**
     * 新增退款记录表数据
     * @param orderRefundInf  退款记录表对象
     * @return
     */
    @Transactional
    public int insertOrderRefundInf(OrderRefundInf orderRefundInf,String token) throws Exception { 
        if(orderRefundInf!=null && (orderRefundInf.getId()==null)){
            orderRefundInf.setId(IdWorker.getId());
        }  
        return this.orderRefundInfMapper.insertOrderRefundInf(orderRefundInf);
    }
    
    /**
     * 更新退款记录表数据
     * @param orderRefundInf 退款记录表对象
     * @return     
     */
    @Transactional
    public int updateOrderRefundInf(OrderRefundInf orderRefundInf,String token) throws Exception {     	
        return  this.orderRefundInfMapper.updateOrderRefundInf(orderRefundInf);
    }    
    /**
     * 查询退款记录表返回key-Value属性
     * @param orderRefundInf 系统操作对象
     * @return     
     */
    public List<CommonKeyValue> optionsOrderRefundInf(OrderRefundInf orderRefundInf,String token) throws Exception {
        List<OrderRefundInf> listOrderRefundInf=this.orderRefundInfMapper.selectListOrderRefundInf(orderRefundInf);
        List<CommonKeyValue> listOptions=new ArrayList<CommonKeyValue>();
        for(OrderRefundInf item:listOrderRefundInf){
            CommonKeyValue opts=new CommonKeyValue();
            opts.setId(""+item.getId());
            opts.setValue(item.getRemark());
            listOptions.add(opts);
        }
        return listOptions;
    }
}
